package com.bestcem.xm.member.controller.v2;

import com.bestcem.xm.common.core.domain.web.XmResultJson;
import com.bestcem.xm.component.security.context.SecurityContextHolder;
import com.bestcem.xm.member.service.MemberService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 校验
 *
 * @author yf.wang <yf.wang@idiaoyan.com>
 * @version V1.0
 * @date 2021/8/5
 */
@Slf4j
@RestController
@RequestMapping("member/v2")
public class ValidController {

    @Resource
    private MemberService memberService;

    /**
     * 校验邮箱是否唯一
     *
     * @param mType
     * @param email
     * @return
     */
    @GetMapping("/email/valid/check")
    public XmResultJson checkEmailValid(@RequestParam("mtype") Integer mType,
                                        @RequestParam("email") String email,
                                        HttpServletRequest request) {
        
        String orgId = SecurityContextHolder.getOrgId();
        return memberService.validateEmail(orgId, mType, email);
    }

    /**
     * 校验手机号是否唯一
     *
     * @param mtype
     * @param mobile
     * @return
     */
    @GetMapping("/mobile/valid/check")
    public XmResultJson checkmobileValid(@RequestParam("mtype") Integer mtype,
                                            @RequestParam("mobile") String mobile,
                                             HttpServletRequest request) {
        
        String orgId = SecurityContextHolder.getOrgId();
        return memberService.validateMobile(orgId, mtype, mobile);
    }
}
